package luogu;

import java.io.*;
import java.util.Scanner;

public class A1113 {
    static int N=10010;
    static int[] h=new int [N];
    static int[] e=new int [100*N];
    static int[] ne=new int [100*N];
    static int idx=1;
    static int[] time=new int[N];
    static int[] q=new int[100*N];//队列
    static int n;//点
    static int m;//边
    static int[] d=new int[N];//标记每个点的入度
    static int hh=0,tt=-1;//队列头尾
    static int res=0;
    static BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter log=new BufferedWriter(new OutputStreamWriter(System.out));

    static void add(int a,int b){
        e[idx]=b;//idx这条边指向b
        ne[idx]=h[a];//头插，与原本第一条边建立联系
        h[a]=idx;
        idx++;
    }

    public static void main(String[] args) throws IOException {
        String s = read.readLine();
        int n= Integer.parseInt(s);
        for(int i=1;i<=n;i++) {
            String[] str = read.readLine().split(" ");
            time[i] = Integer.parseInt(str[1]);
            if (str.length > 3) {
                for (int j = 2; j <= str.length - 2; j++) {
                    add(Integer.parseInt(str[j]), i);
                }
                //统计该点的入度

            }
              d[i]=str.length-3;
        }
        momo();
            System.out.println();

        //数据记录完成

    }
        static void momo(){
        //入度为0的入队

            int max=Integer.MIN_VALUE;
               for(int i=1;i<=n;i++){
                          if(d[i]==0){
                              //获取时间最大值
                              q[++tt]=i;
                              //入队
                                 max=Math.max(max,time[i]);

                          }
               }
               res +=max;
               max=0;
               while(hh<=tt){
                        //获取队列头
                   int head=q[hh++];
                   for(int edge=h[head];edge!=-1;edge++){
                                  int end=e[edge];
                                  d[end]--;
                                  
                   }
               }
               
        }
}






















